package com.sts.service;
import java.util.HashMap;
/**
 * 用户service实现
 */
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.sts.bean.User1;
import com.sts.dao.I2user;
import com.sts.dao.IUserDao;
@Service
public class UserService implements IUserService {

	
	
	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource
	private IUserDao IuserDao ;
	@Resource
	private I2user i2 ;
	
	@Override
	public User1 isUser(String user_name, String user_password) {
		User1 result = new User1() ;
		log.debug("user isUser service in");
		
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("user_name", user_name);
		map.put("user_password", user_password) ;
		result = i2.selectUser2(map);
		
		
		log.debug("user isUser service out");
		return result;
	}

	@Override
	public List<User1> selectUserListS(String id,String user_name) {
		log.debug("user selectUserListS service in");
		Map<String,Object> map = new HashMap<String, Object>();
		if(id == null){
			id = "";
		}
		if(user_name == null){
			user_name = "";
		}
		map.put("id", id);
		map.put("user_name", user_name) ;
		log.debug(map);
		List<User1> list = i2.selectUser1List(map) ;
		
		log.debug("user selectUserListS service out");
		return list;
	}

	@Override
	public boolean deleteUserS(String id) {
		log.debug("deleteUserS service in");
		boolean result = false ;
		
		int a = 0 ;
		a = i2.deleteUser(id);
		if(a == 1){
			result = true ;
		}
		
		
		log.debug("deleteUserS service out");
		return result;
	}

	@Override
	public int selectSize(String id, String user_name) {
		Map<String,Object> map = new HashMap<String, Object>() ;
		if(id == null){
			id = "";
		}
		if(user_name == null){
			user_name = "";
		}
		map.put("id", id) ;
		map.put("user_name", user_name) ;
		int result = i2.selectSize(map) ;
		return result;
	}

	
	/**
	 * 插入一条用户信息
	 */
	@Override
	public int insertUser(User1 user) {
		log.debug("insertUser1 service in" );
		int result = i2.insertUser1(user);
		log.debug("insertUser1 service out" );
		return result;
	}

	@Override
	public int updatetUser(User1 user) {
		log.debug("insertUser1 service in" );
		log.debug(user);
		int result = i2.updateUser(user);
		log.debug("insertUser1 service out" );
		return result;
	}

}
